package com.nuoniu.sibanyun.controller.erp.in;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.in.InInventoryCategory;
import com.nuoniu.sibanyun.service.erp.in.IInInventoryCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 存货分类 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-06-12
 */
@RestController
@RequestMapping("/in/inventoryCategory")
@Api(tags = "存货分类管理")
public class InInventoryCategoryController extends BaseController {
    
    @Autowired
    private IInInventoryCategoryService inventoryCategoryService;

    /**
     * 获取存货分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @GetMapping("getInventoryCategoryList")
    @ApiOperation(value = "获取存货分类列表")
    public HttpResult<InInventoryCategory> getInventoryClassList() {
        return HttpResult.ok(inventoryCategoryService.getInventoryCategoryList());
    }

    /**
     * 保存存货分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @PostMapping("save")
    @ApiOperation(value = "保存存货分类")
    public HttpResult save(@RequestBody InInventoryCategory inInventoryClass) {

        if(StringUtils.isBlank(inInventoryClass.getName())) {
            throw new NuoNiuException("存货分类名称不能为空");
        }
        if(StringUtils.isBlank(inInventoryClass.getCode())) {
            throw new NuoNiuException("存货分类编码不能为空");
        }

        inventoryCategoryService.saveInventoryCategory(inInventoryClass);
        return HttpResult.ok();
    }

    /**
     * 删除存货分类
     * @author 小啊刚
     * @date 2020-09-23
     */
    @GetMapping("delete")
    @ApiOperation(value = "删除存货分类")
    public HttpResult delete(@ApiParam(name="id",value="存货分类id",required=true)Integer id, @ApiParam(name="parentId",value="上级id")Long parentId) {
        if(id == null) {
            throw new NuoNiuException("id不能为空");
        }

        inventoryCategoryService.deleteById(id);
        return HttpResult.ok();
    }
}
